<html>
<head><meta charset="utf-8"><title>function being turned into unreachable by LLVM · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/function.20being.20turned.20into.20unreachable.20by.20LLVM.html">function being turned into unreachable by LLVM</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="211356016"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/function%20being%20turned%20into%20unreachable%20by%20LLVM/near/211356016" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/function.20being.20turned.20into.20unreachable.20by.20LLVM.html#211356016">(Sep 26 2020 at 11:33)</a>:</h4>
<p>While working on a very simple program for my study I found a miscompilation. LLVM turned a function into an <code>ud2</code> instruction. I think this is LLVM finding an infinite loop without side-effects. I am not sure if I can share the program right now, but how can I check if it is indeed caused by an infinite loop turned into <code>unreachable</code> by LLVM?</p>



<a name="211356124"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/function%20being%20turned%20into%20unreachable%20by%20LLVM/near/211356124" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/function.20being.20turned.20into.20unreachable.20by.20LLVM.html#211356124">(Sep 26 2020 at 11:36)</a>:</h4>
<p>Nope, the loop does actually finish.</p>



<a name="211356322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/function%20being%20turned%20into%20unreachable%20by%20LLVM/near/211356322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/function.20being.20turned.20into.20unreachable.20by.20LLVM.html#211356322">(Sep 26 2020 at 11:43)</a>:</h4>
<p>Apart from <code>assert_eq!</code>, <code>#[test]</code> and the <code>Range</code>/<code>RangeFrom</code> types the standard library is not used at all. It is just an incorrect fibonacci implementation and another function that uses that fibonacci implementation.</p>



<a name="211356382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/function%20being%20turned%20into%20unreachable%20by%20LLVM/near/211356382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/function.20being.20turned.20into.20unreachable.20by.20LLVM.html#211356382">(Sep 26 2020 at 11:44)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/131828-t-compiler/topic/function.20being.20turned.20into.20unreachable.20by.20LLVM/near/211356124">said</a>:</p>
<blockquote>
<p>Nope, the loop does actually finish.</p>
</blockquote>
<p>Wait, that is only the test for the broken fibonacci implementation. The test for the other function does indeed go into an infinite loop.</p>



<a name="211363400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/function%20being%20turned%20into%20unreachable%20by%20LLVM/near/211363400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/function.20being.20turned.20into.20unreachable.20by.20LLVM.html#211363400">(Sep 26 2020 at 14:48)</a>:</h4>
<p>easiest way to manually add side effects to a loop as a programmer is to add a volatile read:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0_</span><span class="k">i32</span><span class="p">;</span><span class="w"></span>
<span class="k">loop</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="p">(</span><span class="o">&amp;</span><span class="n">x</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="kt">i32</span><span class="p">).</span><span class="n">read_volatile</span><span class="p">();</span><span class="w"></span>
<span class="w">  </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="211363420"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/function%20being%20turned%20into%20unreachable%20by%20LLVM/near/211363420" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/function.20being.20turned.20into.20unreachable.20by.20LLVM.html#211363420">(Sep 26 2020 at 14:48)</a>:</h4>
<p>Fixing the fibonacci implementation was enough to prevent the miscompilation.</p>



<a name="211383640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/function%20being%20turned%20into%20unreachable%20by%20LLVM/near/211383640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nikita Popov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/function.20being.20turned.20into.20unreachable.20by.20LLVM.html#211383640">(Sep 26 2020 at 21:33)</a>:</h4>
<p>FWIW there is a non-zero chance that this issue will be fixed in LLVM 12.</p>



<a name="211388590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/function%20being%20turned%20into%20unreachable%20by%20LLVM/near/211388590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/function.20being.20turned.20into.20unreachable.20by.20LLVM.html#211388590">(Sep 27 2020 at 00:00)</a>:</h4>
<p>Is there any discussion to read on this?</p>



<a name="211388594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/function%20being%20turned%20into%20unreachable%20by%20LLVM/near/211388594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/function.20being.20turned.20into.20unreachable.20by.20LLVM.html#211388594">(Sep 27 2020 at 00:00)</a>:</h4>
<p>Must have missed it.</p>



<a name="211391711"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/function%20being%20turned%20into%20unreachable%20by%20LLVM/near/211391711" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/function.20being.20turned.20into.20unreachable.20by.20LLVM.html#211391711">(Sep 27 2020 at 01:34)</a>:</h4>
<p><span class="user-mention" data-user-id="123586">@nagisa</span> perhaps starting at <a href="https://github.com/rust-lang/rust/issues/28728#issuecomment-669799725">https://github.com/rust-lang/rust/issues/28728#issuecomment-669799725</a> ?</p>



<a name="211397513"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/function%20being%20turned%20into%20unreachable%20by%20LLVM/near/211397513" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/function.20being.20turned.20into.20unreachable.20by.20LLVM.html#211397513">(Sep 27 2020 at 04:16)</a>:</h4>
<p>I think this thread on <code>maynotprogress</code>:<br>
<a href="http://lists.llvm.org/pipermail/llvm-dev/2020-September/thread.html#144865">http://lists.llvm.org/pipermail/llvm-dev/2020-September/thread.html#144865</a></p>



<a name="211397526"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/function%20being%20turned%20into%20unreachable%20by%20LLVM/near/211397526" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/function.20being.20turned.20into.20unreachable.20by.20LLVM.html#211397526">(Sep 27 2020 at 04:18)</a>:</h4>
<p>Though IIRC the consensus was heading toward flipping that to an opt-in <code>mustprogress</code></p>



<a name="211415258"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/function%20being%20turned%20into%20unreachable%20by%20LLVM/near/211415258" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/function.20being.20turned.20into.20unreachable.20by.20LLVM.html#211415258">(Sep 27 2020 at 12:52)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116155">Jake Goulding</span> <a href="#narrow/stream/131828-t-compiler/topic/function.20being.20turned.20into.20unreachable.20by.20LLVM/near/211391711">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="123586">nagisa</span> perhaps starting at <a href="https://github.com/rust-lang/rust/issues/28728#issuecomment-669799725">https://github.com/rust-lang/rust/issues/28728#issuecomment-669799725</a> ?</p>
</blockquote>
<p>Changesets adding alpha-equivalent attributes have been popping up for the past 5 years. None of them landed so far, so I don’t have many hopes for this specific one either.</p>



<a name="211415349"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/function%20being%20turned%20into%20unreachable%20by%20LLVM/near/211415349" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/function.20being.20turned.20into.20unreachable.20by.20LLVM.html#211415349">(Sep 27 2020 at 12:55)</a>:</h4>
<p>without a proper consensus from many people, that is.</p>



<a name="211429521"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/function%20being%20turned%20into%20unreachable%20by%20LLVM/near/211429521" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nikita Popov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/function.20being.20turned.20into.20unreachable.20by.20LLVM.html#211429521">(Sep 27 2020 at 19:04)</a>:</h4>
<p><span class="user-mention" data-user-id="123586">@nagisa</span> <a href="https://reviews.llvm.org/D86233">https://reviews.llvm.org/D86233</a></p>



<a name="211429596"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/function%20being%20turned%20into%20unreachable%20by%20LLVM/near/211429596" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nikita Popov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/function.20being.20turned.20into.20unreachable.20by.20LLVM.html#211429596">(Sep 27 2020 at 19:06)</a>:</h4>
<p>The spec change towards not requiring forward progress by default is already approved, the rest is just a matter of time now...</p>



<a name="211437521"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/function%20being%20turned%20into%20unreachable%20by%20LLVM/near/211437521" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/function.20being.20turned.20into.20unreachable.20by.20LLVM.html#211437521">(Sep 27 2020 at 22:27)</a>:</h4>
<p>cool, lovely</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>